﻿//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Licensed under the MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once
#include "GmStructure.h"
#include "NdbObjectSchematic.h"
#include "IExternalData.h"
#include "IStructureInstanceBuildingStoreyData.h"
#include "DbDataSchema.h"
#include "RegenDataSchema.h"
#include "RegenDataId.h"

namespace gcmp
{
    class IParameter;

    class StructureInstanceBuildingStoreyData : public NdbObjectSchematic, public IExternalData, public IStructureInstanceBuildingStoreyData
    {
        DBOBJECT_DATA_BEGIN_AND_QUICK_CAST_FROM(gcmp, StructureInstanceBuildingStoreyData, gcmp::NdbObjectSchematic, 427EBDE5 - A82D - 4EAF - B08C - C378F01CC67D, gmstructure, IExternalData)
            DATA_TRANSIENT(IElement*, pOwnerElement)
            DATA_REGEN_OVERRIDE(ElementId, BuildingStoreyId)
        DBOBJECT_DATA_END

    public:
        static StructureInstanceBuildingStoreyData* Create(IInstance* pInstance, ElementId buildingStoreyId);
        static StructureInstanceBuildingStoreyData* Get(IInstance* pInstance);
        static const StructureInstanceBuildingStoreyData* Get(const IInstance* pInstance);

        virtual void SetBuildingStoreyId(ElementId buildingStoreyId) override { SetBuildingStoreyId__(buildingStoreyId);  MarkBuildingStoreyIdRdId(); }
        virtual ElementId GetBuildingStoreyId() const override { return GetBuildingStoreyId__(); }

    private:
        StructureInstanceBuildingStoreyData(IInstance* pInstance, ElementId buildingStoreyId);

        virtual bool SetOwnerElement(IElement* pOwnerElement) override;
        virtual IElement* GetOwnerElement() override;
        virtual const IElement* GetOwnerElement() const override;
        IDocument* GetDocument() const;
        ElementId GetOwnerElementId() const;
        virtual NdbObject* GetTopOwnerObject() const override;

    private:
        virtual void ReportElementIds(std::set<ElementId>* pElementIds, std::unordered_map<ElementId, std::vector<std::wstring>, ElementIdHash>* pPaths,
            std::vector<std::wstring>* pCurrentPath) const final {}
        virtual void ReplaceElementIds(const std::unordered_map<ElementId, ElementId, ElementIdHash>& oldToNewMap) final {}

        virtual void UpdateForWeakParentDeletion(const std::set<ElementId>& deletedElementIds) override;
        virtual void ReportParents(IElementParentReporter& reporter) const override;
        virtual void GetCalculators(ICalculatorCollection* calculators) const override;

        virtual void ReportParameterDefinitions(std::vector<int>* pParamDefIds) const override;
        virtual OwnerPtr<IParameter> GetNativeParameter(int paramDefId) const override;
        virtual bool SetNativeParameter(const IParameter *param, std::wstring* errorMsg = nullptr) override;
        virtual bool IsParameterModifiable(int paramDefId) const override;

        virtual void Report(const gcmp::ICopyContext & copyContext, gcmp::ICopyStrategyReporter& reporter) const override;
        virtual void UpdateAfterCopy(const ICopyContext& copyContext) override {};
        virtual void UpdateForWeakParentCopied(const IDocument* pDocumentFrom, const IElement* pSource, const IElement* pCopy) const override {};
        virtual bool ShouldBeCopiedTogether(const ICopyContext & copyContext) const override { return true; };
        virtual bool IsStrongParentsNeedCopied(void) const override { return true; };
        virtual bool CanBeCopied(std::wstring* pErrorMessage) const override { return true; };
        virtual bool Transform(const Matrix4d& matrix) override { return true; }

    };
}
